package com.liu.service.impl;

import com.liu.api.common.jdbc.Timeout;
import com.liu.api.pojo.Users;
import com.liu.mapper.UsersMapper;
import com.liu.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author liubo
 */
@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    @Transactional(timeout = Timeout.LEVEL_FOUR, propagation = Propagation.REQUIRED, rollbackFor = {Throwable.class })
    public void addUsers(List<Users> usersLs) {
        usersMapper.insertUsers(usersLs);
    }

    @Override
    @Transactional(timeout = Timeout.LEVEL_FOUR, propagation = Propagation.REQUIRED, rollbackFor = {Throwable.class })
    public void delUsers(String userId) {
        usersMapper.insertUsersHis(userId);
        usersMapper.deleteUsers(userId);
    }

    @Override
    @Transactional(timeout = Timeout.LEVEL_FOUR, propagation = Propagation.REQUIRED, rollbackFor = {Throwable.class })
    public void modifyUsers(Users users) {
        usersMapper.insertUsersHis(users.getUserId());
        usersMapper.updateUsers(users);
    }

    @Override
    public int queryUsersCount(Users users) {
        return usersMapper.selectUsersCount(users);
    }

    @Override
    public List<Users> queryUsers(Users users) {
        return usersMapper.selectUsers(users);
    }
}
